package com.my.bo.impl;

import java.math.BigInteger;
import java.sql.Date;
import java.util.List;

import com.my.bean.Order;
import com.my.bean.OrderAccepted;
import com.my.bean.OrderBack;
import com.my.bo.OrderBo;

public class OrderBoImpl extends BaseBo implements OrderBo {

	/***************************************** Order ***************************************************************************/

	@Override
	public Order getOrderById(Class<Order> c, Integer id) throws Exception {
		return orderdao.getOrderById(c, id);
	}

	@Override
	public boolean addOrder(Order order) throws Exception {
		Date date = new Date(System.currentTimeMillis());
		order.setNo("test");
		order.setDate(date);
		order.setState("未受理");
		userdao.addUser(order.getUser());
		orderdao.addOrder(order);
		String number = String.format("%tY%<tm%<td%03d", date, order.getId());
		order.setNo(number);
		return true;
	}

	@Override
	public BigInteger getTotalOrderRecords() throws Exception {
		return orderdao.getTotalOrderRecords();
	}

	@Override
	public List<Order> getAllOrderByPage(int pageindex, int pagesize)
			throws Exception {
		return orderdao.getAllOrderByPage(pageindex, pagesize);
	}

	@Override
	public BigInteger searchTotalOrderRecords(Order Order) throws Exception {
		return orderdao.searchTotalOrderRecords(Order);
	}

	@Override
	public List<Order> searchOrderByPage(int pageindex, int pagesize,
			Order Order) throws Exception {
		return orderdao.searchOrderByPage(pageindex, pagesize, Order);
	}

	@Override
	public boolean orderAccepted(OrderAccepted orderaccepted) throws Exception {
		Order order = orderdao.getOrderById(Order.class, orderaccepted
				.getOrder().getId());
		order.setState("已受理");
		orderaccepted.setDate(new Date(System.currentTimeMillis()));
		orderaccepted.setState("未反馈");
		if (orderaccepteddao.addOrderAccepted(orderaccepted)) {
			return true;
		}
		return false;
	}

	@Override
	public BigInteger getTotalOrderRecords2() throws Exception {
		return orderdao.getTotalOrderRecords2();
	}

	@Override
	public List<Order> getAllOrderByPage2(int pageindex, int pagesize)
			throws Exception {
		return orderdao.getAllOrderByPage2(pageindex, pagesize);
	}

	@Override
	public BigInteger searchTotalOrderRecords2(Order Order) throws Exception {
		return orderdao.searchTotalOrderRecords2(Order);
	}

	@Override
	public List<Order> searchOrderByPage2(int pageindex, int pagesize,
			Order Order) throws Exception {
		return orderdao.searchOrderByPage2(pageindex, pagesize, Order);
	}

	@Override
	public BigInteger getTotalOrderRecords3() throws Exception {
		return orderaccepteddao.getTotalOrderAcceptedRecords();
	}

	@Override
	public List<OrderAccepted> getAllOrderByPage3(int pageindex, int pagesize)
			throws Exception {
		return orderaccepteddao.getAllOrderAcceptedByPage(pageindex, pagesize);
	}

	@Override
	public BigInteger searchTotalOrderRecords3(OrderAccepted orderAccepted)
			throws Exception {
		return orderaccepteddao.searchTotalOrderAcceptedRecords(orderAccepted);
	}

	@Override
	public List<OrderAccepted> searchOrderByPage3(int pageindex, int pagesize,
			OrderAccepted orderAccepted) throws Exception {
		return orderaccepteddao.searchOrderAcceptedByPage(pageindex, pagesize,
				orderAccepted);
	}

	@Override
	public OrderAccepted getOrderAcceptedById(Class<OrderAccepted> c, Integer id)
			throws Exception {
		return orderaccepteddao.getOrderAcceptedById(c, id);
	}

	@Override
	public boolean addOrderBack(OrderBack orderback) throws Exception {
		OrderAccepted orderaccepted = orderaccepteddao.getOrderAcceptedById(
				OrderAccepted.class, orderback.getOrderaccepted().getId());
		orderaccepted.setState("已反馈");
		orderback.setDate(new Date(System.currentTimeMillis()));
		if (orderbackdao.addOrderBack(orderback)) {
			return true;
		}
		return false;
	}

	@Override
	public BigInteger getTotalOrderRecords4() throws Exception {
		return orderbackdao.getTotalOrderBackRecords();
	}

	@Override
	public List<OrderBack> getAllOrderByPage4(int pageindex, int pagesize)
			throws Exception {
		return orderbackdao.getAllOrderBackByPage(pageindex, pagesize);
	}

	@Override
	public BigInteger searchTotalOrderRecords4(OrderBack orderback)
			throws Exception {
		return orderbackdao.searchTotalOrderBackRecords(orderback);
	}

	@Override
	public List<OrderBack> searchOrderByPage4(int pageindex, int pagesize,
			OrderBack orderback) throws Exception {
		return orderbackdao.searchOrderBackByPage(pageindex, pagesize,
				orderback);
	}

}
